package com.example.day03;

import java.util.Calendar;
import java.util.Date;

public class DateDemo {
    public static void main(String[] args) {

        //1. 通过new关键字创建一个日期对象

        Date date=new Date();
        System.out.println(date);
        //2.通过指定的年月日创建

        Date date2=new Date(2020-1900,1,1);
        System.out.println(date2);

        //3。Date 类型转换为毫秒
        Date date1=new Date(1000000000000L);
        System.out.println(date1);
        //获取当前年份
        System.out.println(date.getYear()+1900);
        //获取当前月份          [0,11]
        System.out.println(date.getMonth());
        //获取当前是几号
        System.out.println(date.getDate());
        //获取当前的星期几
        System.out.println(date.getDay());
         //获取当前的毫秒数 距离1970
        System.out.println(date.getTime());


        System.out.println();
        setTime(1000000L);

        Calendar calendar=Calendar.getInstance();
        calendar.set(2022,7,20);
        Date date3=Calendar.getInstance().getTime();
        System.out.println(date3);




    }

    private static void setTime(long l) {
        long time=l;
        System.out.println(new Date(time));
    }

}
